﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Dynamic;
using Facebook;
using JOthello.FB;

namespace JOthello.Forms.FB
{
    public partial class FacebookLoginForm : Form
    {
        #region getter / setter
        public FacebookOAuthResult FacebookOAuthResult { get; private set; }
        #endregion

        public FacebookLoginForm()
        {
            InitializeComponent();

            this.Icon = Properties.Resources.icon;

            login();
        }
        
        public void login()
        {
            wbrFacebook.Navigate(JOthello.FB.FBHelper.LoginUri.AbsoluteUri);
        }

        private void wbrFacebook_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            FacebookOAuthResult oauthResult;
            if (FBHelper.FBC.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                FacebookOAuthResult = oauthResult;
                FBHelper.AccessToken = FacebookOAuthResult.AccessToken;
                DialogResult = FacebookOAuthResult.IsSuccess ? DialogResult.OK : DialogResult.No;
                this.Close();
            }
            else
            {
                FacebookOAuthResult = null;
            }
        }
    }
}
